//
// Created by grg on 2020/8/3.
// Copyright (c) 2020 龚任根. All rights reserved.
//

#ifndef TEST_CPP_PROJECT_IBLOCKPART_H
#define TEST_CPP_PROJECT_IBLOCKPART_H

#include <iostream>
#include "IBlock.h"

class IBlockPart : public IBlock {

private:
    IBlockPart *next = nullptr;


public:
    IBlockPart() {
    }

    ~IBlockPart() {

        cout << "销毁 IBlockPart" << endl;

        if (next != nullptr) {
            next->kill();
        }
    }

public:
    void insertToChain(IBlockPart *target) {
        if (this->next == nullptr) {
            this->next = target;
        } else {
            this->next->insertToChain(target);
        }
    }

public:
    virtual void kill() = 0;


public:
    virtual void onEvent(const SDL_Event *event) override {
        this->event(event);
        if (next != nullptr) {
            next->onEvent(event);
        }
    }

    void onDraw() override {
        this->draw();
        if (next != nullptr) {
            next->onDraw();
        }
    }

    void onPreUpdate() override {
        this->update();
        if (next != nullptr) {
            next->onPreUpdate();
        }
    }

protected:
    virtual void event(const SDL_Event *event) = 0;

    virtual void draw() = 0;

//
    virtual void update() = 0;

};

#endif //TEST_CPP_PROJECT_IBLOCKPART_H
